Socket
Socket
Sign inDemoInstall

Deferred

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Deferred

A port of the jQuery Deferred library to node js.


Version published
Weekly downloads
61
decreased by-24.69%
Maintainers
1
Weekly downloads
 
Created
Source

jQuery Deferred Library for Node js.

website

jQuery Deferred solves the following problems:

  • support common deferred interface in node
  • give some access to the deferred library underpinning in the browser

Usage :

var Deferred = require('Deferred');
var when = Deferred.when;

var dfd = new Deferred() // || Deferred()
dfd.done( function () {
	alert("Deferred resolved!");
} ).fail( function () {
	alert("Deferred rejected!");
} );

setTimeout( function(){
	dfd.resolve();
}, 1500 );

Slightly more meaningful Usage Case :

var fs = require('fs');

function readFile(fileName){
	var hasReadFile = new Deferred();
	fs.readFile(fileName, 'utf8',function(err, contents){
		if ( err !== null ) {
			return hasReadFile.reject(err);
		}
		return hasReadFile.resolve(contents);
	});
	return hasReadFile.promise();
}

function parseFile(fileName, parser){
	// parser implemented elsewhere
	readFile(fileName)
		.done(parser.parse)
		.fail(function(err){
			console.error('readFile :: ', err);
		});
}

What are Deferreds?

I am putting together a small list of articles worth reading about the concept of deferreds, futures and promises. In it's simplest form a deferred object is a way to introduce a callback stack to a function.

ColonelPanic

Keywords

FAQs

Package last updated on 05 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc